package edu.hitsz.aircraft;

import edu.hitsz.bullet.BaseBullet;
import edu.hitsz.basic.AbstractFlyingObject;
import edu.hitsz.prop.AbstractProp;
import edu.hitsz.shoot.ShootStrategy;

import java.util.List;

/**
 * 所有种类飞机的抽象父类：
 * 敌机（BOSS, ELITE, MOB），英雄飞机
 *
 * @author hitsz
 */
public abstract class AbstractAircraft extends AbstractFlyingObject {
    /**
     * 生命值
     */
    protected int maxHp;
    protected int hp;

    /** 战机类型 英雄战机:0 普通敌机:1 精英战机:2 Boss战机:3 */
    protected int type;

    /** 攻击方式 */
    protected int shootNum;
    protected int power;
    protected int direction;


    protected ShootStrategy shootStrategy;


    public AbstractAircraft(int locationX, int locationY, int speedX, int speedY, int hp) {
        super(locationX, locationY, speedX, speedY);
        this.hp = hp;
        this.maxHp = hp;

    }


    /**  遭受攻击 生命值受损 */
    public void decreaseHp(int decrease){
        hp -= decrease;
        if(hp <= 0){
            hp=0;
            vanish();
        }
    }

    /**  恢复生命值 */
    public void refreshHp(int refresh){
        hp += refresh;
        if(hp>maxHp) {
            hp = maxHp;
        }
    }

    public int getHp() {
        return hp;
    }

    @Override
    public int getType() {return type; }


    /**
     * 飞机射击方法，可射击对象必须实现
     * @return
     *  可射击对象需实现，返回子弹 子弹存在链表里
     *  非可射击对象空实现，返回null
     */
    public List<BaseBullet> shoot() {
        return shootStrategy.shoot(locationX,locationY,speedY,shootNum,power,direction);
    }


    public AbstractProp dropProp(){
        return null;
    }

    public boolean isShootScattering() { return (this.shootNum > 1); }

    @Override
    public boolean isAircraft() {
        return true;
    }
}


